﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Collections.Generic;
using Telerik.Web.UI;

public partial class main_dataStatistics_HJQX : System.Web.UI.Page
{

    protected void Page_Load(object sender, EventArgs e)
    {

        if (!IsPostBack)
        {
            RadGrid1.Visible = false;
            LinkButton4.Visible = false;
            LineDAOs lineDAOs = LineDAOs.getInstance();
            List<String> lineList = lineDAOs.getLineNameList();
            for (int i = 0; i < lineList.Count; i++)
            {
                DropDownList1.Items.Add(lineList[i]);
            }
        }
    }
    protected void UpdateGridView(String metrics)
    {
        //RadGrid1.Columns.Clear();
        DataTable dataTable;
        if (metrics.Equals("温度")) {
            LineDAOs lineDAOs = LineDAOs.getInstance();
            dataTable = lineDAOs.getDTDataStatisticsHJQX(DropDownList1.SelectedValue, "温度", RadDatePicker1.SelectedDate.Value, RadDatePicker2.SelectedDate.Value);
            RadGrid1.DataSource = dataTable;
            RadGrid1.DataBind();
        }
        else if(metrics.Equals("风速")){
            LineDAOs lineDAOs = LineDAOs.getInstance();
            dataTable = lineDAOs.getDTDataStatisticsHJQX(DropDownList1.SelectedValue, "风速", RadDatePicker1.SelectedDate.Value, RadDatePicker2.SelectedDate.Value);
            RadGrid1.DataSource = dataTable;
            RadGrid1.DataBind();
        }
        else if(metrics.Equals("雨量")){
            LineDAOs lineDAOs = LineDAOs.getInstance();
            dataTable = lineDAOs.getDTDataStatisticsHJQX(DropDownList1.SelectedValue, "雨量", RadDatePicker1.SelectedDate.Value, RadDatePicker2.SelectedDate.Value);
            RadGrid1.DataSource = dataTable;
            RadGrid1.DataBind();
        }
    }





    protected void RadGrid1_PageIndexChanged(object source, GridPageChangedEventArgs e)
    {
        RadGrid1.CurrentPageIndex = e.NewPageIndex;
        UpdateGridView(HiddenField_M.Value);
    }
    protected void RadGrid1_PageSizeChanged(object source, GridPageSizeChangedEventArgs e)
    {
        UpdateGridView(HiddenField_M.Value);
    }
    //单击显示图形按钮时发生

    protected void LinkButton1_Click(object sender, EventArgs e)
    {
        UpdateGridView("温度");
        RadGrid1.Visible = true;
        HiddenField_M.Value = "温度";
        LinkButton4.Visible = true;
    }

    protected void LinkButton2_Click(object sender, EventArgs e)
    {
        UpdateGridView("风速");
        RadGrid1.Visible = true;
        HiddenField_M.Value = "风速";
        LinkButton4.Visible = true;

    }
    protected void LinkButton3_Click(object sender, EventArgs e)
    {
        UpdateGridView("雨量");
        RadGrid1.Visible = true;
        HiddenField_M.Value = "雨量";
        LinkButton4.Visible = true;

    }
    protected void LinkButton4_Click(object sender, EventArgs e)
    {
        if (RadGrid1.Visible == true)
        {
            RadGrid1.ExportSettings.ExportOnlyData = false;
            RadGrid1.ExportSettings.IgnorePaging = true;
            UpdateGridView(HiddenField_M.Value);
            RadGrid1.MasterTableView.ExportToCSV();
        }
    }
    protected void RadGrid1_ItemCommand(object source, GridCommandEventArgs e)
    {
        if (e.CommandName.Equals("Select"))
        {
            Session["aLineName"] = ((GridDataItem)e.Item)["线路名称"].Text;
            Session["aTowerName"] = ((GridDataItem)e.Item)["杆塔名称"].Text;
            Session["aType"] = HiddenField_M.Value;
            Session["aTimeBegin"] = RadDatePicker1.SelectedDate.Value;
            Session["aTimeEnd"] = RadDatePicker2.SelectedDate.Value;
            Response.Redirect("./AlarmDuration.aspx");
        }
    }
}
